-- Done with aVoN and his garbage tables in mind :3

-- Set up the proper font resize, and also create variables
FontResize = (ScrW()/1280)
surface.CreateFont("Default",FontResize*25,400,true,false,"WraithFont");
surface.CreateFont("stargate",FontResize*27,400,true,false,"AtlantisFont");
surface.CreateFont("Default",FontResize*25,400,true,false,"AmmoFont");
surface.CreateFont("akbar",FontResize*10,400,true,false,"ScoreFont");

WHITE = Color(255,255,255,255)
WRAITH = Color(75,94,1,255)
RED = Color(255, 60, 60, 255)
GREEN = Color(60, 255, 60, 255)
BLACKTRANS = Color( 0, 0, 0, 100 )

SGFONT = "AtlantisFont"

function DrawHealth()
	if LocalPlayer():Health() == nil or LocalPlayer():Health() <= 0 then return end -- if we are dead then break
	local health = (LocalPlayer():Health() * 2.6)
	draw.RoundedBox(6, x*.2, y*.895, math.Clamp(health, 1, 260 ), 70, RED) -- draw our beautiful health box

end

function DrawAmmo() -- FIX ME
	if LocalPlayer():GetActiveWeapon():Clip1() == nil then return end
	local BeAmmo = LocalPlayer():GetActiveWeapon():Clip1() * LocalPlayer():GetActiveWeapon():Clip1()
	local Ammo = math.Clamp(BeAmmo, 1, 260)
	
	draw.RoundedBox(6, x*.636, y*.895, Ammo, 70, GREEN)
end

scol = 255

function DrawSpectateBox()

	Spectating = LocalPlayer():GetNWBool("spectating")
	local w = ScrW()
	local h = ScrH()
	
	if Spectating then
	
		scol = math.Approach(scol, 255, FrameTime() * 30)
		
	else
	
		scol = math.Approach(scol, 0, FrameTime() * 30)
		
	end
	
	if scol != 0 then 
	
		draw.RoundedBox( 0, 0, 0, w, h, Color( 0, 0, 0, scol ) )
		
	end
	
end

function DrawKillView( killer, teamkilled )

	local kNick = killer:Nick()
	local kTeam = killer:GetTeamName()
	local kClass = killer:WWGetClass()
	local kHealth = killer:Health()
	local kWep = WW.Weapons[killer:GetActiveWeapon():GetClass()] or killer:GetActiveWeapon():GetClass()
	local kKills = killer:Frags()
	local kDeaths = killer:Deaths()
	
	local x = ScrW() - 400
	KVy = math.Approach(KVy, 70, FrameTime() * 70)
	
	draw.RoundedBox(4, x, KVy, 250, 120, BLACKTRANS)
	
	draw.DrawText("Killer: " .. kNick, "NText", x + 5, KVy + 5, WHITE, 0)
	draw.DrawText("Team: " .. kTeam, "NText", x + 5, KVy + 20, WHITE, 0)
	draw.DrawText("Class: " .. kClass, "NText", x + 5, KVy + 35, WHITE, 0)
	draw.DrawText("Health: " .. kHealth, "NText", x + 5, KVy + 50, WHITE, 0)
	draw.DrawText("Weapon: " .. kWep, "NText", x + 5, KVy + 65, WHITE, 0)
	draw.DrawText("Kills: " .. kKills, "NText", x + 5, KVy + 80, WHITE, 0)
	draw.DrawText("Deaths: " .. kDeaths, "NText", x + 5, KVy + 95, WHITE, 0)
	
end

function StartKillView(UM)
	
	local killer = UM:ReadEntity()
	local teamkilled = UM:ReadBool()
	local KVy = 0
	local StartTime = CurTime()
	
	local function Draw()
		local TimeRunning = CurTime() - StartTime
		print(TimeRunning)
		local kNick = killer:Nick()
		local kTeam = killer:GetTeamName()
		local kClass = killer:WWGetClass()
		local kHealth = killer:Health()
		local kWep = WW.Weapons[killer:GetActiveWeapon():GetClass()] or killer:GetActiveWeapon():GetClass()
		local kKills = killer:Frags()
		local kDeaths = killer:Deaths()
		
		local x = ScrW() - 400
		if TimeRunning <= 5 then KVy = math.Approach(KVy, 70, FrameTime() * 70) else KVy = math.Approach(KVy, 0, FrameTime() * 70) end
		
		draw.RoundedBox(4, x, KVy, 250, 120, BLACKTRANS)
		
		draw.DrawText("Killer: " .. kNick, "NText", x + 5, KVy + 5, WHITE, 0)
		draw.DrawText("Team: " .. kTeam, "NText", x + 5, KVy + 20, WHITE, 0)
		draw.DrawText("Class: " .. kClass, "NText", x + 5, KVy + 35, WHITE, 0)
		draw.DrawText("Health: " .. kHealth, "NText", x + 5, KVy + 50, WHITE, 0)
		draw.DrawText("Weapon: " .. kWep, "NText", x + 5, KVy + 65, WHITE, 0)
		draw.DrawText("Kills: " .. kKills, "NText", x + 5, KVy + 80, WHITE, 0)
		draw.DrawText("Deaths: " .. kDeaths, "NText", x + 5, KVy + 95, WHITE, 0)
		
		if TimeRunning >= 7 then hook.Remove("HUDPaint", "KillViewPaint") end
	end
	hook.Add("HUDPaint", "KillViewPaint", Draw)
	
end
usermessage.Hook("_KillView", StartKillView)

--################# HUD @Prefanatic/KP3
function GM:HUDPaint()	
	GAMEMODE:HUDDrawTargetID()  -- O shit, don't want to forget about this stuff.
	--GAMEMODE:HUDDrawPickupHistory() 
	GAMEMODE:DrawDeathNotice( 0.85, 0.04 ) 
	
	x = ScrW() -- more vairables
	y = ScrH()
	
	self = LocalPlayer()
	plyHealth = 0
	plyFrags = 0
	WraithScore = 0
	AtlantisScore = 0
	PrimaryAmmo = 0
	SecondaryAmmo = 0
	PrimaryClip = 0
	WeaponName = ""
	
	if self:GetNWBool("disconnected") then return false end
	
	if self:GetActiveWeapon() != NULL then -- if we don't have a weapon, don't do this shit
	if self:GetActiveWeapon() == NULL then return end -- just incase
		plyHealth = self:Health()
		plyFrags = self:Frags()
		WraithScore = self:GetNWInt("wraithscore")
		AtlantisScore = self:GetNWInt("wraithscore")
		PrimaryAmmo = self:GetActiveWeapon():Clip1()
		SecondaryAmmo = self:GetActiveWeapon():Clip2()
		PrimaryClip = self:GetAmmoCount(self:GetActiveWeapon():GetPrimaryAmmoType())
		WeaponName = self:GetActiveWeapon():GetPrintName()
	end

	
	if PrimaryAmmo == -1 then
		PrimaryAmmo = PrimaryClip
	end
	
	DrawSpectateBox()
	
	if WW.Flavor.Name == "Stargate Atlantis" then -- if we are using the Stargate Atlantis plugin
		
		/* ============================================================
						Create Fonts
		=============================================================*/				-- NOTICE, Wraith HUD is OFFLINE!  Waiting for new HUD style.

		/* ============================================================
						Create Wraith Hud
		=============================================================*/
		/*if self:Team() >= 20 and self:Team() < 29 and self:Alive() then
			local hud = surface.GetTextureID("stargatedm/squarewraith")
			
			surface.SetTexture(hud)
			surface.SetDrawColor(255,255,255,255)
			surface.DrawTexturedRect(0, 0, x, y)

			draw.DrawText("HEaLTH", "WraithFont", x*.163, y*.94, WRAITH, 1)
			draw.DrawText(plyHealth, "AmmoFont", x*.163, y*.87,WRAITH, 1)
			
			draw.DrawText("Kills", "WraithFont", x*.78, y*.94, WRAITH, 1)
			draw.DrawText(plyFrags, "AmmoFont", x*.78, y*.87, WRAITH, 1)
			
			draw.DrawText("Score", "WraithFont", x*.64, y*.94, WRAITH, 1)
			draw.DrawText(WraithScore, "AmmoFont", x*.64, y*.87, WRAITH, 1)
			
			draw.DrawText("Ammo", "WraithFont", x*.35, y*.94, WRAITH, 1)
			draw.DrawText(PrimaryAmmo, "AmmoFont", x*.35, y*.87, WRAITH, 1)
			
			draw.DrawText(WeaponName, "WraithFont", x*.5, y*.87, WRAITH, 1)*/
		if self:Team() >= 10 and self:Team() < 19 and self:Alive() then -- if we are appart of the atlantis team
		
			--DrawHealth()
			--DrawAmmo()
			
			if LocalPlayer():GetNWString("hascontentpack") == "true" then 
				local hud = surface.GetTextureID("stargateww/astlantian05") -- set material
				
				surface.SetTexture(hud) -- set it again
				surface.SetDrawColor(255,255,255,255) -- colors!
				surface.DrawTexturedRect(0, 0, x, y) -- Set the possition
			end
			
			draw.DrawText("HEALTH:", SGFONT, x*.08, y*.915, WHITE, 1) -- draw our shit
			draw.DrawText(plyHealth .. "%", "AmmoFont", x*.17, y*.915, WHITE, 1)
		
			draw.DrawText("ATLANTIS:", SGFONT, x*.39, y*.05, WHITE, 1)
			draw.DrawText(AtlantisScore, "AmmoFont", x*.46, y*.05, WHITE, 1)
			
			draw.DrawText(":WRAITH", SGFONT, x*.64, y*.05, WHITE, 1)
			draw.DrawText(WraithScore, "AmmoFont", x*.58, y*.05, WHITE, 1)
			
			draw.DrawText(":AMMO", SGFONT, x*.935, y*.915, WHITE, 1)
			if PrimaryAmmo != 0 then
				draw.DrawText(PrimaryAmmo, "AmmoFont", x*.83, y*.915, WHITE, 1)
				if PrimaryClip != 0 then
					draw.DrawText("/ " .. PrimaryClip, "AmmoFont", x*.87, y*.915, WHITE, 1)
				end
			elseif PrimaryAmmo == 0 and PrimaryClip != 0 then
				draw.DrawText("RELOAD!", "AtlantisFont", x*.85, y*.915, WHITE, 1)
			else
				draw.DrawText("NO AMMO!", "AtlantisFont", x*.85, y*.915, WHITE, 1)
			end
			
			if self:Team() == 10 then
				CurCredits = self:GetNWInt("credits")
				
				draw.DrawText("CREDITS:", SGFONT, x*.08, y*.8, WHITE, 1)
				draw.DrawText(CurCredits, "AmmoFont", x*.17, y*.8, WHITE, 1)
			end
			
		end
		
		/* ============================================================
							Create Score up Top
		=============================================================*/
		if self:Team() >= 20 and self:Team() < 29 and self:Alive() then
		draw.RoundedBox(8, (ScrW()/2) - (130/2), 10, 130, 50, Color(0, 0, 0, 100))
		draw.DrawText("Atlantis Score: " .. AtlantisScore, "ScoreFont", (ScrW()/2), 15, Color(255,255,255,255), 1)
		draw.DrawText("Wraith Score: " .. WraithScore, "ScoreFont", (ScrW()/2), 35, Color(255,255,255,255), 1)
		end

	end
end

function GM:HUDShouldDraw(name)
	self = LocalPlayer()
	if (name == "CHudHealth" or
		name == "CHudBattery" or
		name == "CHudSuitPower" or
		name == "CHudAmmo" or
		(HelpToggled and name == "CHudChat")) then
			return false
	else
		return true
	end
end